/*
 * main_window.h
 *
 *  Created on: 12.06.2013
 *      Author: SpirTanol
 */

#ifndef MAIN_WINDOW_H_
#define MAIN_WINDOW_H_

// QT
#include <QMainWindow>

#include "events/data_event_listener.h"
#include "global.h"

class QTabWidget;
class QLabel;
class QLineEdit;
class QToolButton;

class TabSearch;
class TabWatch;
class TabSetup;
class TabCharCurve;
class TabCrashCurve;

class DataThread;
class DeviceInfo;
class DataEvent;

class DataEventGetProtocol;
class ConfigPacket;

class MainWindow : public QMainWindow, public DataEventListener
{
	Q_OBJECT

	QTabWidget *oTabWidget;

	TabSearch *oTabSearch;
	TabWatch *oTabWatch;
	TabSetup *oTabSetup;
	TabCharCurve *oTabCharCurve;
	TabCrashCurve *oTabCrashCurve;

	DataThread *oThread;

	QLabel *oLabelConnection;

	EventList oProtocol;

	QLineEdit *oEditPassword;

	QToolButton *oBtnReport;

public:
	MainWindow();
	~MainWindow();

	void showMessage(const QString &msg, int time = 5000);

	void connectToDevice(const DeviceInfo *dev);
	void disconnectFromDevice();

	void updateProtocol(const DataEventGetProtocol *e);
	void addEvent(ProtocolEvent *e);

	void readConfig();
	void writeConfig(ConfigPacket *packet);
	void writeTime(uint time);

	bool hasPassword() const;

	const DeviceInfo *deviceInfo() const;

	void resetCrashProtocol();
	void resetWorkProtocol();
	void resetWorkTime();

	void changeAppendOut();
	void commandEngine(int command);

	void focusEditPassword();

	void runAutoConfig();

private:
	void createUI();
	void createToolBar();

	void saveLastConnection();
	void loadLastConnection();

	void updateTitle();

private slots:
	void onDataEvent(const DataEvent *e); // [virtual]
	void onPasswordEditingFinished();

	void onBtnCreateReport();
	void onBtnShowAppConfig();
	void onBtnShowHelp();

};

#endif /* MAIN_WINDOW_H_ */
